<!--
* @description:新增销项发票
* @fileName: NewSalesInvoice
* @author:石锦涛
* @date:2022-01-11
* @后台人员:石锦涛
-->
<template>
  <div>
    <!-- 新增销项发票 -->
    <el-row :span="1">
      <el-col :span="5">客户名称:</el-col>
      <el-col :span="10"
        ><el-input v-model="jieshu.InvoiceUnitx"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="5">发票类型:</el-col>
      <el-col :span="10">
        <el-radio-group v-model="jieshu.InvoiceType">
          <el-radio :label="0">普通发票</el-radio>
          <el-radio :label="1">增值税发票</el-radio>
        </el-radio-group>
      </el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="5">发票金额:</el-col>
      <el-col :span="10"
        ><el-input v-model="jieshu.InvoiceMoneyx"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="5">税率:</el-col>
      <el-col :span="10"
        ><el-input v-model="jieshu.TaxRatex"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="5">税额:</el-col>
      <el-col :span="10"><el-input v-model="suiliu"></el-input></el-col>
      <el-col :span="2"
        ><el-button @click="xinshuju()">显示税额</el-button></el-col
      >
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="5">开票日期:</el-col>
      <el-col :span="10"
        ><el-input type="Date" v-model="jieshu.MakeInvoiceTimex"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="5">备注:</el-col>
      <el-col :span="10"
        ><el-input type="textarea" v-model="jieshu.Remarkzx"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3"
        ><el-button @click="addjiashu()">提交</el-button></el-col
      >
      <el-col :span="1"><el-button @click="fanhui()">取消</el-button></el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      jieshu: {
        PinBanks: "",
        InvoiceUnitx: "",
        InvoiceType: "",
        InvoiceMoneyx: "",
        TaxRatex: "",
        TaxQuantityx: "",
        MakeInvoiceTimex: "",
        Remarkzx: "",
        PreparedDyrx: "1",
        IsDelete: "0",
      },
      suiliu: "",
    };
  },
  methods: {
    //跟新
    xinshuju() {
      this.suiliu = this.jieshu.TaxRatex * this.jieshu.InvoiceMoneyx;
    },
    //添加草稿
    addjiashu() {
      if (this.jieshu.InvoiceUnitx.length === 0) {
        alert("客户名称不能为空");
        return;
      }
      if (this.jieshu.InvoiceType.length === 0) {
        alert("发票类型不能为空");
        return;
      }
      if (this.jieshu.InvoiceMoneyx.length === 0) {
        alert("发票金额不能为空");
        return;
      }
      var retNum = /^\d+(\.\d+)?$/; //匹配数字匹配数字(包括小数)/^\d*$/
      if (!retNum.test(this.jieshu.InvoiceMoneyx)) {
        alert("发票金额只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.TaxRatex.length === 0) {
        alert("税率不能为空");
        return;
      }
      if (!retNum.test(this.jieshu.TaxRatex)) {
        alert("税率只能是正数,整数,小数");
        return;
      }
      if (this.suiliu.length === 0) {
        alert("税额不能为空");
        return;
      }
      if (this.jieshu.MakeInvoiceTimex.length === 0) {
        alert("开票日期不能为空");
        return;
      }
      if (this.jieshu.Remarkzx.length === 0) {
        alert("备注不能为空");
        return;
      }
      this.jieshu.TaxQuantityx = this.suiliu;
      this.$axios
        .post(
          "https://localhost:44399/api/app/new-sales-app/new-sales",
          this.jieshu
        )
        .then((res) => {
          if (res.data.Code > 0) {
            alert("添加成功");
            this.$router.push("/SalesInvoiceManagement");
          } else {
            alert("添加失败");
          }
        });
    },
    //返回管理
    fanhui() {
      this.$router.push("/SalesInvoiceManagement");
    },
  },
  created() {},
};
</script>

<style>
</style>